package com.libraries.entities;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class FormInfo {

	// 上传文件的数据
	private File file;
	private byte[] data;
	private InputStream inStream;

	// 文件名称
	private String fileName;

	// 请求参数名称
	private String paramName;

	// 内容类型
	private String contentType = "application/octet-stream";

	/**
	 * 
	 * 上传小文件，把文件数据先读入内存
	 * 
	 * @param filname
	 * 
	 * @param data
	 * 
	 * @param parameterName
	 * 
	 * @param contentType
	 */
	
	public FormInfo(){
		
	}

	public FormInfo(String fileName, byte[] data, String paramName,
			String contentType) {

		this.data = data;
		this.fileName = fileName;
		this.paramName = paramName;
		
		if (contentType != null)
			this.contentType = contentType;
	}

	/**
	 * 
	 * 上传大文件，一边读文件数据一边上传
	 * 
	 * @param filname
	 * @param file
	 * @param parameterName
	 * @param contentType
	 */

	public FormInfo(String fileName, File file, String parameterName,
			String contentType)
	{
		this.file = file;
		this.fileName = fileName;
		this.paramName = parameterName;
		try
		{
			this.inStream = new FileInputStream(file);
		}

		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		if (contentType != null)
			this.contentType = contentType;
	}

	public File getFile()
	{
		return file;
	}

	public InputStream getInStream()
	{
		return inStream;
	}

	public byte[] getData()
	{
		return data;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getParamName() {
		return paramName;
	}

	public void setParamName(String paramName) {
		this.paramName = paramName;
	}

	public String getContentType()
	{
		return contentType;
	}

	public void setContentType(String contentType)
	{
		this.contentType = contentType;
	}

}
